// pages/my/index.js
const App = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		userInfo: {
			wxLoginOpenid: "",
			wxUserId: "",
			wxLoginUsername: "",
			wxLoginImg: "",
			wxLoginPhone: "",
			navTop: 0,
			navContentHeight: 0,
			placeholderHeight: 0,
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		let a = [{
				"route": "pages/my/index"
			},
			{
				"route": "pages/login/index"
			},
		];
		let def = 0
		for (let i = a.length; i > 0; i--) {
			if (a[i - 1].route != "pages/login/index") {
				break
			}
			def = def + 1
		}
		console.log(def)

		this.setData({
			navTop: App.globalData.navTop,
			navContentHeight: App.globalData.navContentHeight,
			options: JSON.stringify(options)
		})
		const query = wx.createSelectorQuery();
		query.select('.head').boundingClientRect();
		query.exec((res) => {
			this.setData({
				placeholderHeight: res[0].height
			})
		});
		// 读取缓存用户信息
		this.setData({
			wxLoginOpenid: App.globalData.user.wxLoginOpenid,
			wxUserId: App.globalData.user.wxUserId,
			wxLoginUsername: App.globalData.user.wxLoginUsername,
			wxLoginImg: App.globalData.user.wxLoginImg,
			wxLoginPhone: App.globalData.user.wxLoginPhone,
		})
	},
	onShow() {
		if (!App.globalData.user.wxLoginPhone) {
			wx.showModal({
				title: '尚未登录',
				content: '请确认是否要登录',
				complete: (res) => {
					if (res.cancel) {

					}

					if (res.confirm) {
						wx.navigateTo({
							url: '/pages/login/index',
						})
					}
				}
			})
		}
		this.setData({
			wxLoginOpenid: App.globalData.user.wxLoginOpenid,
			wxUserId: App.globalData.user.wxUserId,
			wxLoginUsername: App.globalData.user.wxLoginUsername,
			wxLoginImg: App.globalData.user.wxLoginImg,
			wxLoginPhone: App.globalData.user.wxLoginPhone,
		})

	},
	// 前往聊天记录
	goChatHisPage() {
		wx.navigateTo({
			url: '/pages/chat/history/index',
		})
	},
	//前往设置页面
	goSetting() {
		wx.navigateTo({
			url: '/pages/my/setting/index',
		})
	},
	//前往个人信息
	goUser() {
		wx.navigateTo({
			url: '/pages/my/user/index',
		})
	},
	//前往收藏
	goCollect() {
		wx.navigateTo({
			url: '/pages/my/collect/index',
		})
	},
	onShareAppMessage(options) {
		// 默认分享配置
		return {
			title: App.globalData.onShareAppMessage.title,
			path: App.globalData.onShareAppMessage.path,
			imageUrl: App.globalData.onShareAppMessage.imageUrl,
		}
	},
})